
#include"cpphttplib/httplib.h"
#include"search.hpp"

const std::string root_path = "/home/cjk/boost-search-engine/wwwroot";
const std::string input_path="/home/cjk/boost-search-engine/raw_html/raw.txt";
int main()
{
  ns_search::Searcher * search = new ns_search::Searcher();
  search->IintSeacher(input_path);

  //测试cpphttplib
  httplib::Server ser;
  ser.set_base_dir(root_path.c_str());
  ser.Get("/s",[&search](const httplib::Request& req,httplib::Response &res){
    
    if(!req.has_param("word"))
    {
      res.set_content("必须要输入关键字","text/plain; charset=utf8");
      return;
    }
    std::string jsonstring;
    std::string word = req.get_param_value("word");
    search->Seach(word,&jsonstring);
    res.set_content(jsonstring,"application/json");
  });
  ser.listen("0.0.0.0",3389);
  return 0;
}




